﻿using System;
using DKE_Kinect.Entwicklung.Core;
using Microsoft.Xna.Framework;

namespace DKE_Kinect.Entwicklung.Kinect.GestureEvents
{
    /// <summary>
    /// Klasse, die Gesten des Linken Arms bereitstellt
    /// </summary>
    /// 

    public class LeftArmGestures : GestureEvent
    {
        /// <summary>
        /// Konstruktor für Gesten des Linken Arms
        /// </summary>
        public LeftArmGestures()
        {
        }

        /// <summary>
        /// Initialisiert LeftArm-Gesten
        /// </summary>
        /// <param name="LeftShoulder">Linke Schulter</param>
        /// <param name="LeftElbow">Linker Ellenbogen</param>
        /// <param name="LeftHand">Linke Hand</param>
        public void LookFor(Vector3 LeftShoulder, Vector3 LeftElbow, Vector3 LeftHand)
        {
            double LeftArmRangeX = (Math.Max(Math.Max(LeftShoulder.X, LeftElbow.X), LeftHand.X) - (Math.Min(Math.Min(LeftShoulder.X, LeftElbow.X), LeftHand.X)));
            double LeftArmRangeY = (Math.Max(Math.Max(LeftShoulder.Y, LeftElbow.Y), LeftHand.Y) - (Math.Min(Math.Min(LeftShoulder.Y, LeftElbow.Y), LeftHand.Y)));
            double LeftArmRangeZ = ((Math.Max(Math.Max(LeftShoulder.Z, LeftElbow.Z), LeftHand.Z) - (Math.Min(Math.Min(LeftShoulder.Z, LeftElbow.Z), LeftHand.Z))));
            double LeftArmRange = (LeftArmRangeX + LeftArmRangeY + LeftArmRangeZ) / 3;


            // Left Hand up (--> Linke Hand geht über Schulterhöhe)
            if (LeftArmRangeX <= LeftArmRange && LeftHand.Y < LeftShoulder.Y && LeftElbow.Y > LeftShoulder.Y && LeftArmRangeY >= LeftArmRange)
            {
                //EVENT
                OnGestureEvent(new GestureEventArgs(Gestures.LeftHandUp, StateManager.CurrMode));
                return;
            }

            // Left Arm out (--> Linker Arm ausgestreckt)
            if (LeftArmRangeY <= LeftArmRange && LeftHand.X < LeftShoulder.X && LeftArmRangeZ <= LeftArmRange && LeftArmRangeX >= LeftArmRange*2)
            {
                //EVENT
                OnGestureEvent(new GestureEventArgs(Gestures.LeftArmOut, StateManager.CurrMode));
                return;
            }

            // Left Arm forward (--> Linker Arm nach vorn gestreckt)
            if (LeftArmRangeX <= LeftArmRange && LeftHand.Z < LeftShoulder.Z && LeftArmRangeY <= LeftArmRange && LeftArmRangeZ >= LeftArmRange*2)
            {
                //EVENT
                OnGestureEvent(new GestureEventArgs(Gestures.LeftArmForward, StateManager.CurrMode));
                return;
            }

            // Left Arm up (--> Linker Arm nach oben gestreckt)
            if (LeftArmRangeX <= LeftArmRange && LeftHand.Y < LeftShoulder.Y && LeftElbow.Y < LeftShoulder.Y && LeftArmRangeZ <= LeftArmRange)
            {
                //EVENT
                OnGestureEvent(new GestureEventArgs(Gestures.LeftArmUp, StateManager.CurrMode));
                return;
            }

        }

    }
}
